/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.csvgenerator.engine.vg;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 *
 * @author Administrator
 */
public class RandomDateValueGenerator extends ValueGenerator {

    private static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    private static DateFormat outputDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    private Long lowerBound = new Long(0);
    private Long upperBound = Long.MAX_VALUE;
    private Float gravity = new Float(1);
    private Long mod = new Long(1);
    private String prefix = "";
    private String suffix = "";

    public RandomDateValueGenerator() {
    }

    @Override
    public String nextValue() {
        String nextValue = "" + ((long) ((upperBound - lowerBound) * new Random().nextFloat() * gravity + lowerBound));
        currentValue = outputDateFormat.format(new Date(Long.parseLong(nextValue)));
        return outputDateFormat.format(new Date(Long.parseLong(nextValue)));
    }

    /**
     * @return the lowerBound
     */
    public Long getLowerBound() {
        return lowerBound;
    }

    /**
     * @param lowerBound the lowerBound to set
     */
    public void setLowerBound(Long lowerBound) {
        this.lowerBound = lowerBound;
    }

    /**
     * @param lowerBound the lowerBound to set
     */
    public void setLowerBound(String lowerBound) {
        try {
            this.lowerBound = dateFormat.parse(lowerBound).getTime();
        } catch (ParseException ex) {
            System.out.println(ex);
        }
    }

    /**
     * @return the upperBound
     */
    public Long getUpperBound() {
        return upperBound;
    }

    /**
     * @param upperBound the upperBound to set
     */
    public void setUpperBound(Long upperBound) {
        this.upperBound = upperBound;
    }

    /**
     * @param upperBound the upperBound to set
     */
    public void setUpperBound(String upperBound) {
        try {
            this.upperBound = dateFormat.parse(upperBound).getTime();
        } catch (ParseException ex) {
            System.out.println(ex);
        }
    }

    /**
     * @return the gravity
     */
    public Float getGravity() {
        return gravity;
    }

    /**
     * @param gravity the gravity to set
     */
    public void setGravity(Float gravity) {
        this.gravity = gravity;
    }

    /**
     * @return the mod
     */
    public Long getMod() {
        return mod;
    }

    /**
     * @param mod the mod to set
     */
    public void setMod(Long mod) {
        this.mod = mod;
    }

    /**
     * @return the prefix
     */
    public String getPrefix() {
        return prefix;
    }

    /**
     * @param prefix the prefix to set
     */
    public void setPrefix(String prefix) {
        this.prefix = prefix;
    }

    /**
     * @return the suffix
     */
    public String getSuffix() {
        return suffix;
    }

    /**
     * @param suffix the suffix to set
     */
    public void setSuffix(String suffix) {
        this.suffix = suffix;
    }
}
